package com.pine.manager.pineframework;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.pine.dao.pineframework.entity.SysUser;
import com.pine.dao.pineframework.mapper.SysUserMapper;
import com.pine.manager.core.BaseManager;
import com.pine.manager.pineframework.bo.SysUserBo;
import com.pine.manager.pineframework.convertors.SysUserConvertor;
import com.pine.manager.pineframework.query.SysUserQuery;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 用户表 管理类
 * </p>
 *
 * @author pine manage
 * @since 2024-08-12
 */
@Component
public class SysUserManager extends BaseManager<SysUserMapper, SysUser, Long, SysUserBo, SysUserQuery, SysUserConvertor> {

    @Resource
    private SysUserConvertor sysUserConvertor;

    @Override
    public LambdaQueryWrapper<SysUser> encapsulateQueryWrapper(SysUserQuery query) {
        LambdaQueryWrapper<SysUser> queryWrapper = super.encapsulateQueryWrapper(query);
        if (query == null) {
            return queryWrapper;
        }

        // 组装查询条件
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getLoginAccount()), SysUser::getLoginAccount, query.getLoginAccount());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getUsername()), SysUser::getUsername, query.getUsername());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getPassword()), SysUser::getPassword, query.getPassword());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getDeptId()), SysUser::getDeptId, query.getDeptId());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getAvatar()), SysUser::getAvatar, query.getAvatar());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getGender()), SysUser::getGender, query.getGender());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getAge()), SysUser::getAge, query.getAge());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getBirthdayStart()), SysUser::getBirthday, query.getBirthdayStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getBirthdayEnd()), SysUser::getBirthday, query.getBirthdayEnd());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getPhone()), SysUser::getPhone, query.getPhone());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getEmail()), SysUser::getEmail, query.getEmail());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getStatus()), SysUser::getStatus, query.getStatus());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getRemark()), SysUser::getRemark, query.getRemark());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getCreateUserId()), SysUser::getCreateUserId, query.getCreateUserId());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getUpdateTimeStart()), SysUser::getUpdateTime, query.getUpdateTimeStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getUpdateTimeEnd()), SysUser::getUpdateTime, query.getUpdateTimeEnd());

        return queryWrapper;
    }
}
